<template>
  <!-- 患者信息---就诊 ---唐莉 -->
  <el-dialog
    :title="type+'记录'"
    :visible="value"
    width="700px"
    custom-class="dialog-box"
    @close="onClose"
    @open="onOpen"
    :close-on-click-modal="false"
    :append-to-body="true"
  >
    <el-form
      ref="form"
      :model="form"
      :rules="rules"
      label-width="120px"
      @submit.native.prevent="onSubmit"
    >
      <el-row>
        <el-col :span="24">
          <el-form-item label="记录时间">
            <el-date-picker
              v-model="form.date"
              type="date"
              :disabled=true
              value-format="yyyy-MM-dd"
              placeholder="选择日期"
            ></el-date-picker>
          </el-form-item>
         
          <!-- <el-button class="btn_sign_option" style="margin-left: 10px;" icon="el-icon-minus"></el-button>
          <el-button class="btn_sign_option" icon="el-icon-plus"></el-button>-->
        </el-col>
        <el-col :span="24" v-if="caseType!==9 && caseType!==6 && caseType!==4">
            <el-form-item :label="typeLable" prop="value">
              <el-input v-model="form.value"></el-input>
            </el-form-item>
        </el-col>
        <el-col :span="24" v-if="caseType==9">
          <el-form-item label="左眼眼视力" prop="leftEye">
              <el-input v-model="form.leftEye"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="caseType==9">
          <el-form-item label="右眼视力" prop="rightEye">
              <el-input v-model="form.rightEye"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="caseType==4">
             <el-form-item label="收缩压" prop="systolicPressure" >
            <el-input v-model="form.systolicPressure"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="caseType==4">
             <el-form-item label="舒张压" prop="diastolicpressure">
            <el-input v-model="form.diastolicpressure"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-button v-show="false" :loading="btnLoading" native-type="submit">提交</el-button>
    </el-form>
    <span slot="footer">
      <el-button type="primary" :loading="btnLoading" @click="onSubmit">确 定</el-button>
    </span>
  </el-dialog>
</template>
<script>
import validate from '@/_js/validate'
export default {
  props: ["value", "curItem", "type", "patientId","typeLable", "caseType"],
  data() {
    return {
      form: {
        value: "",
        date: "",
        signId: "", //体征详情id
        patientId: "",
        signsType:'',//体征类型:1身高 2 体重 3温度 4 血压 5 视力
        weight: "", //体重
        height: "", //身高
        bmi: "",
        temperatureType: "2", //体温类型 1口温 2腋温 3肛温 4耳温 5额温
        temperature: "", //体温
        breathing: "", //呼吸(次/分钟)
        systolicPressure: "", //收缩压
        diastolicpressure: "", //舒张压
        oxygenSaturation: "", //氧饱和度(%)
        painScore: "", //疼痛评分
        leftEye: "", //视力
        rightEye: "", //视力
        pulse: "", //脉搏
        bloodsugar: "" //血糖
      },
      rules: {
        value:[{ required: true, message: "请输入值", trigger: "blur" },
          { validator: validate.integerAndFloat, trigger: "blur" },
          { min: 2, max: 5, message: "请输入正确的值", trigger: "blur" }],
        leftEye:[{ required: true, message: "请输入视力", trigger: "blur" },
          { validator: validate.integerAndFloat, trigger: "blur" },
          { min: 1, max: 4, message: "请输入正确的视力", trigger: "blur" }],
        rightEye:[{ required: true, message: "请输入视力", trigger: "blur" },
          { validator: validate.integerAndFloat, trigger: "blur" },
          { min: 1, max: 4, message: "请输入正确的视力", trigger: "blur" }],
        systolicPressure:[{ required: true, message: "请输入收缩压", trigger: "blur" },
          { validator: validate.integerAndFloat, trigger: "blur" },
          { min: 1, max: 4, message: "请输入正确的收缩压", trigger: "blur" }],
        diastolicpressure:[{ required: true, message: "请输入舒张压", trigger: "blur" },
          { validator: validate.integerAndFloat, trigger: "blur" },
          { min: 1, max: 4, message: "请输入正确的舒张压", trigger: "blur" }],

      },
      btnLoading: false
    };
  },
  created(){
    let th=this;
    th.form.date=th.getNewDate()
  },
  methods: {
    onClose() {
      let th = this;
      th.$refs["form"].resetFields();
      th.$emit("input", false);
    },
    onOpen() {},
    onSubmit() {
      let th = this;
      th.form.signsType=th.caseType;
      switch (th.caseType) {
        case 1:
          th.form.height = th.form.value;
          break;
        case 2:
           th.form.weight = th.form.value;
          break;
        case 3:
          th.form.temperature = th.form.value;
          break;
        case 4:
          th.form.systolicPressure = th.form.systolicPressure;
          th.form.diastolicpressure= th.form.diastolicpressure;
          // th.form.breathing = th.form.value;
          break;
        case 5:
          th.form.pulse = th.form.value;
          break;
        case 6:
          // th.form.systolicPressure = th.form.value;
          break;
        case 7:
          th.form.signsType=4;
          break;
        case 8:
          th.form.painScore = th.form.value;
          break;
        case 9:
          th.form.signsType=5;
          break;
      }
      let j = {};
      th.btnLoading=true;
      th.form.patientId=th.patientId
      Object.assign(j, th.form);
      th.$api.savePatientSignRecord(j).then(res => {
        if(res.executed){
          th.$message.success("保存成功");
          th.$emit("success")
          th.onClose();
          th.btnLoading=false;
        }else{
           th.$message.error(res.message);
            th.onClose();
            th.btnLoading=false;
        }
      }).catch(error=>{
        th.btnLoading=false;
      });
    }
  }
};
</script>
<style lang="scss" scoped>
.btn_sign_option {
  padding: 10px;
}
</style>